
/**
 {{ method_description }}

 {% if params|length == 1 -%}
 - Parameter {{ params[0].name.lower_camel_case }}:{{ params[0].description.rstrip() }}
 {% elif params|length > 1 -%}
 - Parameters:
    {%- for param in params %}
    - {{ param.name.lower_camel_case }}:{{ param.description.rstrip() }}
    {%- endfor %}
 {% endif %}
 */
public func {{ name.lower_camel_case }}({% for param in params %}{{ param.name.lower_camel_case }}: {{ param.type_info.name }}{{ ", " if not loop.last }}{% endfor %}) -> Single<{{ return_type.name }}> {
    return Single<{{ return_type.name }}>.create { single in
        {% if params|length > 0 %}var{% else %}let{% endif %} request = {{ package.upper_camel_case.replace('_', '').replace('.', '_') }}_{{ name.upper_camel_case }}Request()

        {% for param in params %}
            {% if param.type_info.is_primitive %}
        request.{{ param.name.lower_camel_case }} = {{ param.name.lower_camel_case }}
            {% else %}
        request.{{ param.name.lower_camel_case }} = {{ param.name.lower_camel_case }}.rpc{{ param.name.upper_camel_case }}
            {% endif %}
        {% endfor %}

        do {
            let response = self.service.{{ name.lower_camel_case }}(request)

            {% if has_result %}
            let result = try response.response.wait().{{ plugin_name.lower_camel_case }}Result
            if (result.result != {{ package.upper_camel_case.replace('_', '').replace('.', '_') }}_{{ plugin_name.upper_camel_case }}Result.Result.success) {
                single(.failure({{ plugin_name.upper_camel_case }}Error(code: {{ plugin_name.upper_camel_case }}Result.Result.translateFromRpc(result.result), description: result.resultStr)))

                return Disposables.create()
            }
            {% endif %}

	    {% if return_type.is_primitive -%}
            let {{ return_name.lower_camel_case }} = try response.response.wait().{{ return_name.lower_camel_case }}
            {% else %}
                {% if return_type.is_repeated -%}
            let {{ return_name.lower_camel_case }} = try response.response.wait().{{ return_name.lower_camel_case }}.map{ {{ return_type.inner_name }}.translateFromRpc($0) }
                {%- else -%}
            let {{ return_name.lower_camel_case }} = try {{ return_type.inner_name }}.translateFromRpc(response.response.wait().{{ return_name.lower_camel_case }})
                {%- endif %}
            {% endif %}
            single(.success({{ return_name.lower_camel_case }}))
        } catch {
            single(.failure(error))
        }

        return Disposables.create()
    }
}
